﻿using System;
using System.Text;

namespace SplitDemo
{
    public class TextSplitter
    {
        static public string Split(string str, int columns)
        {
            if (str.Length <= columns)
                return str;
            int space = str.Substring(0, columns+1).LastIndexOf(" ");
            if (space > -1)
                return str.Substring(0, space) + "\n" + Split(str.Substring(space + 1), columns);
            return str.Substring(0, columns) + "\n" + Split(str.Substring(columns), columns);
        }
    }
}
